package cn.itcast.service.impl;
import cn.itcast.dao.UserDao;
import cn.itcast.domain.*;
import cn.itcast.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    /**
     * 顾客登录
     * @param name
     * @param pwt
     * @return
     */
    @Override
    public Customer Userlogin(String name, String pwt) {
         return userDao.finduserbyAll(name, pwt);
    }

    /**
     * 获取顾客登录信息
     * @param login_name
     * @return
     */
    @Override
    public Customer fetchUserinfoByName(String login_name) {
        return userDao.findUserByname(login_name);
    }

    @Override
    public Boolean register(User user) {
        return userDao.adduser(user);
    }

    /**
     * 查找原材料
     * @return
     */
    @Override
    public List<Yuancailiao> findmatserial() {
        return userDao.findml();
    }

    /**
     * 删除原材料
     * @param id
     * @return
     */
    @Override
    public Boolean deletemat(Integer id) {
        return userDao.delmat(id);
    }

    @Override
    public Yuancailiao findmaterById(Integer id) {
        return userDao.findmlById(id);
    }

    /**
     * 修改原材料
     * @param yl
     * @return
     */
    @Override
    public Boolean modifymater(Yuancailiao yl) {
        return userDao.modifyma(yl);
    }

    /**
     * 查找原材料总数
     * @return
     */
    @Override
    public Integer findcount() {

        return userDao.findcot();
    }


    /**
     * 主页模糊查询
     * @return
     */
    @Override
    public List<Dishes> findFood(String crux) {
        return userDao.findfoot(crux);

    }

    /**
     * 加入购物车
     * @param id
     * @return
     */
    @Transactional
    @Override
    public Boolean addcart(Integer id) {
        Dishes dishes=userDao.findDishesByid(id);
        Integer fid=dishes.getFoodid();
        String name=dishes.getName();
        String image = dishes.getImage();
        Integer price = dishes.getPrice();
        return userDao.insertCart(fid,name,image,price);
    }

    /**
     * 查找购物车的物品
     * @return
     */
    @Override
    public List<Cart> findshop() {
        return userDao.findshops();
    }

    /**
     * 查找所有菜品
     * @return
     */
    @Override
    public List<Dishes> findFoodByAll() {
        return userDao.finAlldishes();
    }

    /**
     * 添加订单
     * @param cid
     * @param oid
     * @param date
     * @param paymentstatus
     * @param address
     * @param price
     * @return
     */
    @Override
    public Boolean addorder(Integer cid, Integer oid, String date, Integer paymentstatus, String address, Integer price) {
        return userDao.addorders(cid,oid,date,paymentstatus,address,price);
    }

    @Override
    public List<Order> findorder() {
        return userDao.findorders();

    }


    /**
     * 查找厨师
     * @param crux
     * @return
     */
    @Override
    public List<Cook> findCook(String crux) {
        return userDao.findcook(crux);
    }

    /**
     * 根据姓名查找顾客
     * @param name
     * @return
     */
    @Override
    public Customer findCustomer(String name) {
        return userDao.findcustomer(name);
    }

    @Override
    public Order findOrderByCid(Integer cid) {

        return userDao.findorderbycid(cid);
    }

    /**
     * 预约厨师
     * @param orderid
     * @param customerid
     * @param cookid
     * @param date
     * @return
     */
    @Override
    public Boolean addAp(Integer orderid, Integer customerid, Integer cookid, String date) {
        return userDao.addappoint(orderid,customerid,cookid,date);
    }

    /**
     * 查找预约信息
     * @return
     */
    @Override
    public List<Appointment> findappoint() {
        return userDao.findap();
    }

    /**
     * 厨师登录
     * @param name
     * @param pwt
     * @return
     */
    @Override
    public Cook cookLogin(String name, String pwt) {
        return userDao.cooklogin(name,pwt);
    }

    @Override
    public Cook fetchCookinfoByName(String login_name) {
     return userDao.fetchCookbyname(login_name);

    }

    /**
     * 后台管理删除菜品
     * @param id
     * @return
     */
    @Override
    public Boolean deletedish(Integer id) {
        return userDao.deletedi(id);
    }

    /**
     * 查找原材料
     * @return
     */
    @Override
    public List<Yuancailiao> findyuancailiao() {
        return userDao.findcailiao();
    }


}

